home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-06 | 2.8 KB | 131 lines | [TEXT/CWIE] |
- //Copyright (c) 1997 Aidan Cully
- //All rights reserved
-
- #include <Events.h>
- #include <QuickDraw.h>
- #include <Windows.h>
- #include <Dialogs.h>
- #include <Menus.h>
- #include <Fonts.h>
- #include "CLApplication.h"
- #include "CLCleanup.h"
- #include "CLActionHandler.h"
- #include "CLKeyboardHandler.h"
- #include "CLMouseHandler.h"
- #include "CLNullHandler.h"
- #include "CLWindowLayer.h"
- #include "CLFloatLayer.h"
- #include "CLModalLayer.h"
-
- TApplication *TApplication::shCurApp = 0l;
-
- TApplication::TApplication()
- {
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- InitDialogs(0l);
- TEInit();
- InitCursor();
- FlushEvents( everyEvent, 0 );
- for( int i= 0; i<16; i++ )
- SetDeviceHandler( 1<<i, 0 );
- shCurApp = this;
- mhKeyboard= new TKeyboardHandler();
- SetDeviceHandler( keyDownMask|keyUpMask|autoKeyMask, mhKeyboard );
- mhMouse= new TMouseHandler();
- SetDeviceHandler( mDownMask|mUpMask, mhMouse );
- SetDeviceHandler( osMask|activMask, this );
- mhNull= new TNullHandler();
- SetDeviceHandler( 1, mhNull );
- ::GetGWorld( &mhWorld, &mhDevice );
- gFloatingWindowLayer= new TFloatingWindowLayer;
- gNormalWindowLayer= new TWindowLayer;
- gFloatingWindowLayer->AddLayer( gNormalWindowLayer );
- gModalWindowLayer= new TModalLayer();
- }
-
- void TApplication::Quit()
- {
- MEventDispatcher::Quit();
- delete mhKeyboard;
- delete mhMouse;
- delete mhNull;
- }
-
- void TApplication::AddBackgrounder( MBackgrounder *item )
- {
- UInt32 data;
-
- if( mBackGrounds.FindIndex( item ) != -1 )
- return;
- mBackGrounds.MoveLast();
- mBackGrounds.AddNext( item );
- }
-
- void TApplication::RemoveBackgrounder( MBackgrounder *item )
- {
- SInt16 index;
-
- index= mBackGrounds.FindIndex( item );
- if( index == -1 )
- return;
- mBackGrounds.GoToElem( index );
- mBackGrounds.Remove();
- }
-
- void TApplication::DispatchEvent( const EventRecord &ev )
- {
- BuildEvent( ev );
- mClean.Clean();
- }
-
- void TApplication::BuildEvent( const EventRecord &ev )
- {
- switch( ev.what ) {
- case osEvt:
- if( ((ev.message>>24)==suspendResumeMessage) ) {
- TBackgroundEvent bev;
- bev.when= ev.when;
- bev.background= (ev.message&resumeFlag)==0;
- MBackgrounder *item;
- if( mBackGrounds.MoveFirst() ) {
- do {
- mBackGrounds.GetData( item );
- item->HandleBackground( &bev );
- } while( mBackGrounds.MoveNext() );
- return;
- }
- } else if( ((ev.message>>24)==mouseMovedMessage) )
- mhMouse->DispatchEvent( ev );
- break;
- case activateEvt:
- /*if( TFloatingWindow::sFloatList.MoveFirst() )
- return;
- TBaseWindow *win=((TBaseWindow*)GetWRefCon( (WindowRef)ev.message ));
- win->MakeActive( (ev.modifiers&activeFlag)==activeFlag );*/
- break;
- }
- }
-
- void TApplication::NewDispatcher()
- {
- }
-
- void TApplication::OldDispatcher()
- {
- }
-
- void TApplication::GetGlobalWorld( GWorldPtr &world, GDHandle &device )
- {
- world= mhWorld;
- device= mhDevice;
- }
-
- GrafPtr TApplication::GetGlobalPort()
- {
- GrafPtr port;
- ::GetWMgrPort( &port );
- return( port );
- }